package com.ktgj.customer.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.customer.domain.Employee;
import com.ktgj.customer.service.IEmployeeThingService;
import com.ktgj.customer.service.ILoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.customer.domain.DdCouponAudit;
import com.ktgj.customer.service.IDdCouponAuditService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2022-09-28
 */
@RestController
@RequestMapping("/ddCouponAudit")
public class DdCouponAuditController extends BaseController
{
    @Autowired
    private IDdCouponAuditService ddCouponAuditService;
    @Autowired
    private IEmployeeThingService employeeThingService;
    @Autowired
    private ILoginService loginService;

    /**
     * 查询【请填写功能名称】列表
     */
//    @PreAuthorize(hasPermi = "customer:audit:list")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody DdCouponAudit ddCouponAudit)
    {
        startPage();
        List<DdCouponAudit> list = ddCouponAuditService.selectDdCouponAuditList(ddCouponAudit);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize(hasPermi = "customer:audit:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DdCouponAudit ddCouponAudit) throws IOException
    {
        List<DdCouponAudit> list = ddCouponAuditService.selectDdCouponAuditList(ddCouponAudit);
        ExcelUtil<DdCouponAudit> util = new ExcelUtil<DdCouponAudit>(DdCouponAudit.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize(hasPermi = "customer:audit:query")
    @GetMapping(value = "/{couponAuditId}")
    public AjaxResult getInfo(@PathVariable("couponAuditId") Long couponAuditId)
    {
        return AjaxResult.success(ddCouponAuditService.selectDdCouponAuditById(couponAuditId));
    }

    /**
     * 新增【请填写功能名称】
     */
//    @PreAuthorize(hasPermi = "customer:audit:add")
//    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(HttpServletRequest request,@RequestBody DdCouponAudit ddCouponAudit)
    {
        String token = request.getHeader("token");
        Employee employee = loginService.getLoginEmployeeByToken(token);
        if (employee == null)
        {
            return AjaxResult.error("登录已过期");
        }
        return toAjax(ddCouponAuditService.insertDdCouponAudit(employee, ddCouponAudit));
    }

    /**
     * 修改【请填写功能名称】
     */
//    @PreAuthorize(hasPermi = "customer:audit:edit")
//    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody DdCouponAudit ddCouponAudit)
    {
        return toAjax(ddCouponAuditService.updateDdCouponAudit(ddCouponAudit));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "customer:audit:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{couponAuditIds}")
    public AjaxResult remove(@PathVariable Long[] couponAuditIds)
    {
        return toAjax(ddCouponAuditService.deleteDdCouponAuditByIds(couponAuditIds));
    }
}
